package com.rc.evcharger.common.enums;

/**
 * Create by Yang on 2018/11/27
 * 1	手动停止	在屏幕上或APP上点结束充电，或刷卡结束
 * 2	枪已经拔出	充电过程中拔枪
 * 3	车辆请求关机	CP信号从6V切到9V
 * 4	达到设定电量	达到设定条件
 * 5	达到设定时间
 * 6	达到设定金额
 * 7	漏电	检测到漏电(漏电流大于30mA),  仅不带电表机型有此故障
 * 8	余额不足	账户余额已用完
 * 9	过流	检测到持续5秒电流大于设定的过流保护值(在 出厂设置 -> 过流值  处设置),若出现此故障,应先检查此设置值是否正确
 * 10	急停	急停按下
 * 11	无电流关机	检测到持续3分钟电流小于1A
 * 12	欠压
 * 13	过压
 * 14	车辆未就绪	桩启动发波后,CP信号一直为9V(20秒后结束充电)
 * 15	电表故障无电流关机	电表通讯异常
 * 16	与TCU通讯故障
 * 17	门禁
 * 18	交流接触器
 * 19	接地故障
 * 20	机箱过温
 * 21	枪过温
 * 22	断路器故障
 * 23	防雷故障
 * 24	描述	说明
 * 25	达到SOC值	已经充满
 * 26	达到总电压
 * 27	达到单体电压
 * 28	绝缘故障	车BMS检测到绝缘故障，应检查DC+ DC- 是否对PE短路或者充电模块有损坏,对于双枪桩还应检查功率分配继电器是否粘连
 * 29	输出连接器过温	车检测到枪座过温，应检查枪是否插紧，桩输出电流是否已超出枪的额定电流
 * 30	BMS元件输出连接器过温
 * 31	枪已拔出	充电中拔枪
 * 32	电池组温度过高	车BMS检测到电池内部过温
 * 33	其它原因	车BMS检测到故障,可能是绝缘故障，过流，过压等
 * 34	电流过大	车BMS检测到过流
 * 35	电压异常	车BMS检测到电压异常，可以是桩没有输出
 * 36	功率过大	车BMS检测到功率过大 (仅普天协议有此故障 如比亚迪E6)
 * 37	手动停止	在屏幕上或APP上点结束充电，或刷卡结束
 * 38	接收完成充电准备报文超时	BMS不闭合继电器,检查辅助电源，24V的BMS如果桩用12V可能会报些故障
 * 39	电池请求停止	车主动停止，但BMS未告知结束原因
 * 40	接收电池充电总状态报文超时	充电中通讯报文超时，若充电过程中经常无规律出现些故障，应检查S+ S- 通讯是否受到干扰(S+ S-不应与功率线并行布线)，必要时S+ S-换用屏蔽线
 * 41	接收电池充电需求报文超时	充电中通讯报文超时, 应检查S+ S-信号线是否接触不良
 * 42	无电流关机/电流过小	检测到电流小于停机电流设定值(在 充电参数设置 -> 终止电流，延迟时间)，若出现此故障,应先检查此设置值是否正确
 * 43	电池组温度过高2	桩通讯BMS数据检测到电池单体过温
 * 44	单体电压过高 	车BMS检测到电池单体过温
 * 45	接收辨识报文超时/连接失败,请检查辅源设置	检查辅助电源设置是否正确, S+ S-信号线是否连接正常
 * 46	接收电池充电参数报文超时	通讯报文超时
 * 47	达到SOC值2	检测到SOC小于停机SOC设定值(在 充电参数设置 -> 终止SOC，延迟时间)，若出现此故障,应先检查此设置值是否正确
 * 48	电池反接	桩在闭合继电器之前检测到继电器外侧电压为负(小于-20V), 应检查DCBUS采样线是否接反 或车有问题
 * 49	电池电压异常	桩在闭合继电器之前检测到继电器外侧电压与BMS测量的实际电压不符，应检查DCBUS采样线是连接正常
 * 50	电压不匹配	检测到电池电压不在模块正常输出电压的范围内，若出现此故障,应先检查 出厂设置 -> 模块最低电压 模块最高和低电压设置是否正确
 * 51	预充超时	在闭合继电器之前桩会先输出把电压升到低于电池电压5V，若出现此故障说明模块不输出或输出电压不正确
 * 52	BRO错误	在桩闭合输出继电器之前BMS又断开内部继电器
 * 53	辅源欠压	检测辅源不输出,应检查辅源1P空开是否跳了
 * 54	辅源过压	检测到辅源过压,检测12V和24V控制线是否交叉，或开关电源有问题
 * 55	泄放回路异常	"模块没泄放功能的机型,检查泄放回路是否正常.
 * 模块有泄放功能的机型,检查模块地址设置是否正常
 * "
 * 56	功率异常	桩检测到输出功率超过出厂设置值。应检查模块是否用错型号,出厂设置正确
 * 57	输出过压
 * 58	输出欠压
 * 59	输出过流
 * 60	输出短路
 * 61	输出电流异常	硬件电流采样值与模块采样值不一致,可能模块地址冲突或硬件电流采样有问题
 * 62	分配单元分过温	双枪或分体桩功率分配继电器过温
 * 63	交流接触器故障
 * 64	输出电压异常	硬件电流采样值与模块采样值不一致,可能模块地址冲突或硬件电压采样有问题
 * 65	计量异常	软件电量统计与电表计量结果相差太多,可以是电表电压或电流采样异常
 * 66	电表故障	电表通讯异常
 * 67	绝缘故障 正极	桩绝缘检测报故障
 * 68	绝缘故障 负极
 * 69	绝缘模块通讯故障
 * 70	绝缘检测欠压	桩绝缘检测时模块不输出
 * 71	急停
 * 72	防雷器故障
 * 73	输出继电器故障
 * 74	门禁异常
 * 75	模块通讯异常
 * 76	功率分配正继电器故障
 * 77	功率分配负继电器故障
 * 78	功率切换失败	从单模式切换到双枪模式超时,模块泄放太慢,或软件问题
 * 79	机箱过温	检测到机箱温度持续5秒超过82度
 * 80	充电枪过温	检测到枪温度持续5秒超过100度
 * 81	接地故障
 * 82	网络异常	充电中断网,结束充电
 * 83	余额不足	账户余额已用完
 * 84	达到设定度数	达到设定条件
 * 85	达到设定时间
 * 86	达到设定金额
 * 87	后台结束	APP结束
 * 80	并充VIN不匹配	双枪同时检测到两把枪不是插到一辆车上
 * 81	并充电压异常	双枪同时检测到两把枪电压不一致
 * 82	VIN码有误
 * 83	VIN码未注册
 * 84	枪电子锁故障
 * 85	平台强制结束
 * 94	启动超时	车辆侧BRO=0xAA准备就绪过久超过3min
 * 95	读卡器故障	读卡器通讯断开
 * 96	水浸故障	充电机检测浸水
 * 97	控制板故障	充电机自检控制板卡存储、时钟等外设故障
 * 98	控制系统通讯异常	设备内部控制板卡间通讯超时故障
 * 99	过充停止	根据设备内部设定达到soc值后设备主动停止
 * 100	系统断电	设备系统断电引起的停充，恢复上电后补充掉电前报告
 * 101	充电控制板状态异常	充电控制板卡上传状态与实际不同步
 * 102	BSM报文超时
 * 103	BSM状态单体电压过低
 * 104	BSM状态SOC过高
 * 105	BSM状态SOC过低
 * 106	车辆检测连接异常	车辆BMS检测充电机接口连接异常
 * <p>
 * <p>
 * <p>
 * <p>
 * <p>
 * <p>
 * <p>
 * <p>
 * <p>
 * 交流桩停止方式补充
 * 200	控制板故障	充电机自检控制板卡存储、时钟等外设故障
 * 201	系统断电	设备系统断电引起的停充，恢复上电后补充掉电前报告
 * 202	CP扰动	枪头接触不良或CP信号送到导致CP信号幅值不稳定
 * 203	倾斜故障
 * 204	网络异常	充电中断网,结束充电
 */
public enum ElecPileStopReasonEnum {

    //todo 交流桩停止原因
    PILE_STOP_0x01(0x01, "手动停止", "在屏幕上或APP上点结束充电，或刷卡结束"),
    PILE_STOP_0x02(0x02, "枪已经拔出", "充电过程中拔枪"),
    PILE_STOP_0x03(0x03, "车辆请求关机", "CP信号从6V切到9V"),
    PILE_STOP_0x04(0x04, "达到设定电量", "达到设定条件"),
    PILE_STOP_0x05(0x05, "达到设定时间", ""),
    PILE_STOP_0x06(0x06, "达到设定金额", ""),
    PILE_STOP_0x07(0x07, "漏电", "检测到漏电(漏电流大于30mA),  仅不带电表机型有此故障"),
    PILE_STOP_0x08(0x08, "余额不足", "账户余额已用完"),
    PILE_STOP_0x09(0x09, "过流", null),
    PILE_STOP_0xA(0xA, "急停", ""),
    PILE_STOP_0xB(0xB, "无电流关机", ""),
    PILE_STOP_0xC(0xC, "欠压", ""),
    PILE_STOP_0xD(0xD, "过压", ""),
    PILE_STOP_0xE(0xE, "车辆未就绪", ""),
    PILE_STOP_0xF(0xF, "电表故障", ""),
    PILE_STOP_0x10(0x10, "与TCU通讯故障", ""),
    PILE_STOP_0x11(0x11, "门禁", ""),
    PILE_STOP_0x12(0x12, "交流接触器", ""),
    PILE_STOP_0x13(0x13, "接地故障", ""),
    PILE_STOP_0x14(0x14, "机箱过温", ""),
    PILE_STOP_0x15(0x15, "枪过温", ""),
    PILE_STOP_0x16(0x16, "断路器故障", ""),
    PILE_STOP_0x17(0x17, "防雷故障", ""),
    PILE_STOP_0x18(0x18, "读卡器故障", ""),


    //todo 直流桩停止原因
    PILE_STOP_0x19(0x19, "达到SOC值", ""),
    PILE_STOP_0x1A(0x1A, "达到总电压", ""),
    PILE_STOP_0x1B(0x1B, "达到单体电压", ""),
    PILE_STOP_0x1C(0x1C, "绝缘故障", ""),
    PILE_STOP_0x1D(0x1D, "输出连接器过温", ""),
    PILE_STOP_0x1E(0x1E, "BMS元件输出连接器过温", ""),
    PILE_STOP_0x1F(0x1F, "枪已拔出", ""),
    PILE_STOP_0x20(0x20, "电池组温度过高", ""),
    PILE_STOP_0x21(0x21, "其它原因", ""),
    PILE_STOP_0x22(0x22, "电流过大", ""),
    PILE_STOP_0x23(0x23, "电压异常", ""),
    PILE_STOP_0x24(0x24, "功率过大", ""),
    PILE_STOP_0x25(0x25, "手动停止", ""),
    PILE_STOP_0x26(0x26, "接收完成充电准备报文超时", ""),
    PILE_STOP_0x27(0x27, "电池请求停止", ""),
    PILE_STOP_0x28(0x28, "接收电池充电总状态报文超时", ""),
    PILE_STOP_0x29(0x29, "接收电池充电需求报文超时", ""),
    PILE_STOP_0x2A(0x2A, "无电流关机/电流过小", ""),
    PILE_STOP_0x2B(0x2B, "电池组温度过高2", ""),
    PILE_STOP_0x2C(0x2C, "单体电压过高 ", ""),
    PILE_STOP_0x2D(0x2D, "接收辨识报文超时/连接失败,请检查辅源设置", ""),
    PILE_STOP_0x2E(0x2E, "接收电池充电参数报文超时", ""),
    PILE_STOP_0x2F(0x2F, "达到SOC值2", ""),
    PILE_STOP_0x30(0x30, "电池反接", ""),
    PILE_STOP_0x31(0x31, "电池电压异常", ""),
    PILE_STOP_0x32(0x32, "电压不匹配", ""),
    PILE_STOP_0x33(0x33, "预充超时", ""),
    PILE_STOP_0x34(0x34, "BRO错误", ""),
    PILE_STOP_0x35(0x35, "辅源欠压", ""),
    PILE_STOP_0x36(0x36, "辅源过压", ""),
    PILE_STOP_0x37(0x37, "泄放回路异常", ""),
    PILE_STOP_0x38(0x38, "功率异常", ""),
    PILE_STOP_0x39(0x39, "输出过压", ""),
    PILE_STOP_0x3A(0x3A, "输出欠压", ""),
    PILE_STOP_0x3B(0x3B, "输出过流", ""),
    PILE_STOP_0x3C(0x3C, "输出短路", ""),
    PILE_STOP_0x3D(0x3D, "输出电流异常", ""),
    PILE_STOP_0x3E(0x3E, "分配单元分过温", ""),
    PILE_STOP_0x3F(0x3F, "交流接触器故障", ""),
    PILE_STOP_0x40(0x40, "输出电压异常", ""),
    PILE_STOP_0x41(0x41, "计量异常", ""),
    PILE_STOP_0x42(0x42, "电表故障", ""),
    PILE_STOP_0x43(0x43, "绝缘故障 正极", ""),
    PILE_STOP_0x44(0x44, "绝缘故障 负极", ""),
    PILE_STOP_0x45(0x45, "绝缘模块通讯故障", ""),
    PILE_STOP_0x46(0x46, "绝缘检测欠压", ""),
    PILE_STOP_0x47(0x47, "急停", ""),
    PILE_STOP_0x48(0x48, "防雷器故障", ""),
    PILE_STOP_0x49(0x49, "输出继电器故障", ""),
    PILE_STOP_0x4A(0x4A, "门禁异常", ""),
    PILE_STOP_0x4B(0x4B, "模块通讯异常", ""),
    PILE_STOP_0x4C(0x4C, "功率分配正继电器故障", ""),
    PILE_STOP_0x4D(0x4D, "功率分配负继电器故障", ""),
    PILE_STOP_0x4E(0x4E, "功率切换失败", ""),
    PILE_STOP_0x4F(0x4F, "机箱过温", ""),
    PILE_STOP_0x50(0x50, "充电枪过温", ""),
    PILE_STOP_0x51(0x51, "接地故障", ""),
    PILE_STOP_0x52(0x52, "网络异常", ""),
    PILE_STOP_0x53(0x53, "余额不足", ""),
    PILE_STOP_0x54(0x54, "达到设定度数", ""),
    PILE_STOP_0x55(0x55, "达到设定时间", ""),
    PILE_STOP_0x56(0x56, "达到设定金额", ""),
    PILE_STOP_0x57(0x57, "后台结束", ""),
    PILE_STOP_0x58(0x58, "并充VIN不匹配", ""),
    PILE_STOP_0x59(0x59, "并充电压异常", ""),
    PILE_STOP_0x5A(0x5A, "VIN码有误", ""),
    PILE_STOP_0x5B(0x5B, "VIN码未注册", ""),
    PILE_STOP_0x5C(0x5C, "枪电子锁故障", ""),
    PILE_STOP_0x5D(0x5D, "平台强制结束", ""),
    PILE_STOP_0x5E(0x5E, "启动超时", ""),
    PILE_STOP_0x5F(0x5F, "读卡器故障", ""),
    PILE_STOP_0x60(0x60, "水浸故障", ""),
    PILE_STOP_0x61(0x61, "控制板故障", ""),
    PILE_STOP_0x62(0x62, "控制系统通讯异常", ""),
    PILE_STOP_0x63(0x63, "过充停止", ""),
    PILE_STOP_0x64(0x64, "系统断电", ""),
    PILE_STOP_0x65(0x65, "充电控制板状态异常", ""),
    PILE_STOP_0x66(0x66, "BSM报文超时", ""),
    PILE_STOP_0x67(0x67, "BSM状态单体电压过低", ""),
    PILE_STOP_0x68(0x68, "BSM状态SOC过高", ""),
    PILE_STOP_0x69(0x69, "BSM状态SOC过低", ""),
    PILE_STOP_0x6A(0x6A, "车辆检测连接异常", ""),


    /**
     * 交流桩停止方式补充
     **/
    PILE_STOP_0xC8(0xC8, "控制板故障", ""),
    PILE_STOP_0xC9(0xC9, "系统断电", ""),
    PILE_STOP_0xCA(0xCA, "CP扰动", ""),
    PILE_STOP_0xCB(0xCB, "倾斜故障", ""),
    PILE_STOP_0xCC(0xCC, "网络异常", "");


    private final Integer code;
    private final String msg;
    private final String detail;

    ElecPileStopReasonEnum(Integer code, String msg, String detail) {
        this.code = code;
        this.msg = msg;
        this.detail = detail;
    }

    /**
     * 解析code
     *
     * @param code
     * @return
     */
    public static String getElecPileStopReasonResult(String code) {
        Integer intCode = Integer.parseInt(code, 16);
        Class<ElecPileStopReasonEnum> enumClass = ElecPileStopReasonEnum.class;
        for (ElecPileStopReasonEnum elecPileStopReasonEnum : enumClass.getEnumConstants()) {
            if (intCode == elecPileStopReasonEnum.getCode()) {
                return elecPileStopReasonEnum.getMsg();
            }
        }
        return "该停止方式未知:" + intCode;

    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public String getDetail() {
        return detail;
    }

    public static void main(String[] args) {
//        Class<ElecPileStopReasonEnum> enumClass = ElecPileStopReasonEnum.class;
//        for (ElecPileStopReasonEnum jzUserEnum : enumClass.getEnumConstants()) {
//            System.out.println(jzUserEnum.getCode() + " " + jzUserEnum.getMsg());
//
//        }
        String elecPileStopReasonResult = ElecPileStopReasonEnum.getElecPileStopReasonResult("57");
        System.out.println(elecPileStopReasonResult);
        System.out.println(0xC8);
    }
}
